<?php

namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;

class AuthApiController extends BaseController
{
    public function getFirstMenus(Request $request)
    {

        return $this->returnJson(1001, '获取菜单成功', []);

    }

    public function getMenuList(Request $request)
    {

        $parent_id = $request::param('parent_ids');
        $data = [[
            "id" => "d1cd3acb-cfb3-11e9-81b3-7cd30abda6a8",
            "is_show" => "1",
            "sort" => 30,
            "parent_ids" => "0",
            "name" => "模版管理",
            "path" => "/google/template",
            "permission" => "ctc_mike_100101,ctc_mike_storeList,ctc_mike_storesInsert,ctc_mike_storesUpdate,ctc_mike_storesGet",
            "parent_id" => "0"
        ], [
            "id" => "00ab336a-d08e-11e9-81b3-7cd30abda6a8",
            "is_show" => "1",
            "sort" => 60,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "用户查询",
            "path" => "/google/user-search1",
            "permission" => "ctc_mike_newStoreList,ctc_mike_storeShopList,ctc_mike_storeShopFormGet,ctc_mike_storeShopFormInsert,ctc_mike_storeShopFormUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda6a8",
            "is_show" => "1",
            "sort" => 90,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "套餐管理",
            "path" => "/google/combo/google/combo",
//            "path" => "/pages/auto-table/google/google/comboList",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda6a1",
            "is_show" => "1",
            "sort" => 90,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "账号管理",
            "path" => "/management/account/google/user",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda6a2",
            "is_show" => "1",
            "sort" => 90,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "订单管理",
            "path" => "/google/order/google/order",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda6a4",
            "is_show" => "1",
            "sort" => 90,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "短信管理",
            "path" => "/management/code/google/msg",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda612",
            "is_show" => "1",
            "sort" => 90,
            "parent_ids" => "0,1,00ec2007-cfb2-11e9-81b3-7cd30abda6a8,44d78a03-cfb2-11e9-81b3-7cd30abda6a8,",
            "name" => "购买套餐",
            "path" => "/google/pay",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ], [
            "id" => "6964ef1c-e023-11e9-81b3-7cd30abda655",
            "is_show" => "1",
            "sort" => 90,
            "name" => "查询历史",
            "path" => "/google/searchLog/google/searchLog",
            "permission" => "ctc_buttJoint_storeShopUserList,ctc_buttJoint_storeList,ctc_buttJoint_storeShopList,ctc_buttJoint_createStoreShopUsersGet,ctc_buttJoint_createStoreShopUsersInsert,ctc_buttJoint_createStoreShopUsersUpdate",
            "parent_id" => "0"
        ]];
        $info = getLoginInfo();
        if (empty($info)) {
            return $this->returnJson(1004, '请先登录');
        }
        if ($info['id'] == 1) {
            return $this->returnJson(1001, '获取菜单成功', $data);
        } else {
            //            $last = time() - $info['pay_time'];
            //            if ($last <= $info['how_long_time']) {
            //                $menusData = [$data[1],$data[7],$data[4],$data[6]];
            //            }else{
            //                $menusData = [$data[1],$data[7],$data[4],$data[6]];
            //            }
            $count = Db::name('user')->where('id', $info['id'])->count();
            if ($count > 0) {
                $menusData = [$data[1], $data[7], $data[3], $data[4], $data[6]];
            } else {
                $menusData = [$data[1], $data[7], $data[4], $data[6]];
            }
        }
        return $this->returnJson(1001, '获取菜单成功', $menusData);

    }

    public function loginInfo(Request $request)
    {
        $userInfo = getLoginInfo();
        if ($userInfo != false) {
            $data['login_name'] = $userInfo['login_name'];
            $data['company_name'] = $userInfo['company_name'];
            $data['how_long_time'] = $userInfo['how_long_time'];
            $data['company_name'] = $userInfo['company_name'];
            $data['industry'] = $userInfo['industry'];
            $data['address'] = $userInfo['address'];
            $data['main_product'] = $userInfo['main_product'];
            $data['max_num'] = $userInfo['max_num'];
            $data['id'] = $userInfo['id'];
            $data['expiration_time'] = toDate($userInfo['how_long_time'] + $userInfo['pay_time']);
            return $this->returnJson(1001, '获取用户信息成功', $data);
        } else {
            return $this->returnJson(1004, '请先登录');
        }

    }


}
